/**
 * 
 */
package menus.common.statemachines;

import java.awt.Graphics;
import java.awt.Stroke;

import menus.common.AbstractMenu;
import fr.lri.swingstates.canvas.CPolyLine;
import fr.lri.swingstates.canvas.Canvas;
import fr.lri.swingstates.sm.transitions.Drag;
import fr.lri.swingstates.sm.transitions.Release;

/**
 * Skeleton for a One-Stroke selection marking menu state machine
 * 
 * @author mathieu
 *
 */
public class OneStrokeStateMachine extends AbstractMenuStateMachine {

	
	/*
	 * The transitions are created outside of their states so they can easily be removed and 
	 * replaced in extending states machine. This also allows to use their action() method.
	 * 
	 *  Be careful though, action() methods using for example this.getPoint() are to be rewritten, 
	 *  because getPoint() doesn't apply to a transition calling it from outside.  
	 */
	
	protected Drag startStroke = new Drag(">> " + SELECTION_STATE){
		@Override
		public void action() {
			mark.lineTo(getPoint());
			gesture.addPoint(getPoint().getX(), getPoint().getY());
		}
	};
	
	protected Release simpleCancel = new Release(">> " + INACTIVE_STATE){};
	
	protected Drag drawStroke = new Drag(){
		@Override
		public void action() {
			System.out.println("drag");
			mark.lineTo(getPoint());
			gesture.addPoint(getPoint().getX(), getPoint().getY());
		}
	};
	
	protected Release endSelection = new Release(">> " + INACTIVE_STATE){
		@Override
		public void action() {
			selected = menu.getItem(gesture);
			
			callGhost(where);
		}
	};
	
	/**
	 * @param menu
	 */
	public OneStrokeStateMachine(Canvas canvas, AbstractMenu menu) {
		super(canvas, menu);
	}

	/**
	 * @param menu
	 * @param treshold
	 */
	public OneStrokeStateMachine(Canvas canvas, AbstractMenu menu, int treshold) {
		super(canvas, menu, treshold);
	}
	
	/**
	 * Adding transitions to match a one stroke selection menu behavior
	 */
	public void upgradeStateMachine(){
		
		triggered.addTransition(startStroke);
		
		triggered.addTransition(simpleCancel);
		
		selection.addTransition(drawStroke);
		
		selection.addTransition(endSelection);
		
	}

}
